package com.yjc.rabbitMQ.one;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author shkstart
 * @create 2022-07-30 10:09
 */
public class Consumer {

    private static final String QUUEUE_NAME = "mirrior_Hello_queue_product *(￣▽￣)";

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.100.138");
        factory.setUsername("admin");
        factory.setPassword("123");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        DeliverCallback deliverCallback = (consumerTag,message) -> {
            String s = new String(message.getBody());
            System.out.println(s);
        };
        CancelCallback cancelCallback = consumerTag -> {
            System.out.println("你被取消了");
        };

        channel.basicConsume(QUUEUE_NAME, true, deliverCallback, cancelCallback);

    }

}
